package io.renren.modules.eightapp.service.impl;

import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.common.utils.ExcelUtils;
import io.renren.modules.eightapp.dao.EiParkInfoDao;
import io.renren.modules.eightapp.dao.EiParkingInfoDao;
import io.renren.modules.eightapp.dto.EiParkingInfoDTO;
import io.renren.modules.eightapp.dto.ExcelDTO;
import io.renren.modules.eightapp.entity.EiParkInfoEntity;
import io.renren.modules.eightapp.entity.EiParkingInfoEntity;
import io.renren.modules.eightapp.service.EiParkingInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 
 *
 * @author Mark 1132115960@gmail.com
 * @since 1.0.0 2022-12-27
 */
@Service
public class EiParkingInfoServiceImpl extends CrudServiceImpl<EiParkingInfoDao, EiParkingInfoEntity, EiParkingInfoDTO> implements EiParkingInfoService {
    @Autowired
    private EiParkingInfoDao eiParkingInfoDao;
    @Autowired
    private EiParkInfoDao eiParkInfoDao;

    @Override
    public QueryWrapper<EiParkingInfoEntity> getWrapper(Map<String, Object> params){
        String parkId = (String)params.get("parkId");

        QueryWrapper<EiParkingInfoEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(parkId), "park_Id", parkId);

        return wrapper;
    }


    @Override
    public List<List<ExcelDTO>> getDataList(Integer id) {
        EiParkInfoEntity eiParkInfoEntity = eiParkInfoDao.selectById(id);

        List<List> lists = ExcelUtils.readExcel(eiParkInfoEntity.getIcon());
        List<ExcelDTO> dataList = eiParkingInfoDao.getDataList(id);

        List<List<ExcelDTO>> data=new ArrayList<>();

        for (List<Integer> l:lists) {
            List<ExcelDTO> list=new ArrayList<>();
            for1:for (int i = 0; i < l.size(); i++) {
                for (ExcelDTO dto:dataList) {
                    if (dto.getParkingId()==l.get(i)){
                        list.add(dto);
                        continue for1;
                    }
                }
                ExcelDTO excelDTO=new ExcelDTO();
                excelDTO.setParkingId(l.get(i));
                list.add(excelDTO);
            }
            data.add(list);
        }
        return data;
    }



}